<template>
  <view class="content">
    <view class="top">
    </view>
    <view class="technologicalProcess"></view>
    <view class="message" v-if="config.registered==1 && config.friended==0">您已完成注册</view>
    <view class="message" v-if="config.registered==1 && config.friended==1">
      您已完成注册和添加健康顾问，欢迎加入人康大家庭
    </view>
    <view class="message" v-if="config.registered==0 && config.friended==1">您已添加健康顾问</view>
    <view class="message" v-if="config.checkResult==3">您已完成注册，不满足活动参与条件</view>
    <view class="button" v-if="config.registered==0"
          @click="to('/pages/newAnswer/register?inviterUnionid='+config.introducerUnionid+'&sheng='+config.shopProvince+config.shopCity+'&shi='+config.shopName+'&deptName='+config.staffName+'&inviterName='+config.introducerName)">
      去注册
    </view>
    <view class="button" v-else-if="config.registered==1 && config.friended==0"
          @click="to('./shopQcode?unionid='+unionid)">去添加健康顾问
    </view>
    <view class="button" v-else @click="toSindex('/pages/sindex/index')">去看看</view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      inviteString: "",
      unionid: "",
      config: {}
    }
  },
  onLoad(e) {
    this.inviteString = e.inviteString
  },
  onShow() {
    this.login()
  },
  methods: {
    //登陆
    login() {
      var _this = this
      uni.login({
        provider: 'weixin',
        success: function (loginRes) {
          _this.check_login(loginRes.code);
        }
      })
    },
    async check_login(code) {
      const {data} = await this.$NoteApi.doRequest("get", "login", {code: code}, 'json', true);
      this.unionid = data.data.unionid
      uni.setStorageSync("token", data.data.token)
      uni.setStorageSync("userInfo", data.data);
      this.check_register()
    },
    //检测注册进度
    async check_register() {
      var data = {
        unionid: this.unionid,
        introduceString: this.inviteString
      }
      const res = await this.$NoteApi.doRequest("post", 'introducedCustomer/introducedCustomerPage', data, 'json', true);
      if (res.data.data.checkResult == 0) {
        uni.showModal({
          content: "链接已失效请联系邀请人获取最新链接",
          success() {
            uni.switchTab({
              url: '/pages/sindex/index'
            })
          }
        })
      }
      this.config = res.data.data
    },
    to(url) {
      uni.navigateTo({
        url: url
      })
    },
    toSindex(url) {
      uni.switchTab({
        url: url
      })
    }
  }
}
</script>

<style>
.content {
  width: 100%;
  height: 100vh;
  overflow: auto;

  background: #E6FFEE;
}

.top {
  width: 100%;
  height: 660upx;
  background-image: url(https://wechat-pictures-1301970825.file.myqcloud.com/wxapp/newMember/bg_user@2x.png);
  background-size: 100% 100%;
  box-sizing: border-box;
  padding-top: 209upx;
}

.technologicalProcess {
  width: 720upx;
  height: 360upx;
  background-image: url(https://wechat-pictures-1301970825.file.myqcloud.com/wxapp/newMember/img_xinyonghucaiyu@2x.png);
  background-size: 100% 100%;
  margin: 0 auto;
  margin-top: -50upx;
  z-index: 10;
}

.message {
  width: 100%;
  text-align: center;
  font-size: 40upx;
  color: #408C7F;
}

.button {
  width: 728upx;
  height: 136upx;
  line-height: 130upx;
  background-image: url(https://wechat-pictures-1301970825.file.myqcloud.com/wxapp/newMember/tab_user@2x.png);
  background-size: 100% 100%;
  margin: 0 auto;
  text-align: center;
  font-size: 52upx;
  font-weight: 700;
  text-shadow: 0px 2px 9px #50A25E;
  color: #fff;
  margin-top: 20upx;
}
</style>
